package com.yunxin.core.infra.persistence.repository.merchant;

import com.yunxin.core.domain.model.merchant.MerchantContactPerson;
import com.yunxin.core.domain.model.merchant.MerchantContactPersonRepository;
import com.yunxin.core.infra.persistence.converter.MerchantConverter;
import com.yunxin.core.infra.persistence.entity.merchant.MerchantContactPersonDO;
import com.yunxin.core.infra.persistence.mapper.merchant.MerchantContactPersonExtendMapper;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Repository;

/**
 * @author zero°
 * @since 2023-07-12
 */
@Repository
@RequiredArgsConstructor
public class MerchantContactPersonRepositoryImpl implements MerchantContactPersonRepository {

    private final MerchantContactPersonExtendMapper merchantContactPersonExtendMapper;

    private final MerchantConverter merchantConverter;

    @Override
    public boolean saveMerchantContactPerson(MerchantContactPerson merchantContactPerson) {
        MerchantContactPersonDO merchantContactPersonDO = merchantConverter.formMerchantContactPerson(merchantContactPerson);
        int count = merchantContactPersonExtendMapper.insertSelective(merchantContactPersonDO);
        merchantContactPerson.setId(merchantContactPersonDO.getId());
        return count > 0;
    }

    @Override
    public boolean updateMerchantContactPerson(MerchantContactPerson merchantContactPerson) {
        MerchantContactPersonDO merchantContactPersonDO = merchantConverter.formMerchantContactPerson(merchantContactPerson);
        int count = merchantContactPersonExtendMapper.updateByPrimaryKeySelective(merchantContactPersonDO);
        return count > 0;
    }

    @Override
    public boolean updateMerchantContactDelPersonByMerchantId(String editor, Long merchantId) {
        int count = merchantContactPersonExtendMapper.updateMerchantContactDelPersonByMerchantId(editor, merchantId);
        return count > 0;
    }
}
